home *** CD-ROM | disk | FTP | other *** search
- *** patchlevel.h Tue Apr 02 11:59:19 1991
- --- ../xroach/patchlevel.h Tue Apr 02 11:57:25 1991
- ***************
- *** 1 ****
- ! #define PATCHLEVEL 0
- --- 1,4 ----
- !
- ! /* @(#)patchlevel.h 1.2 4/2/91 11:57:18 */
- !
- ! #define PATCHLEVEL 1
- *** roachmap.h Tue Apr 02 11:59:19 1991
- --- ../xroach/roachmap.h Tue Apr 02 11:55:42 1991
- ***************
- *** 1,3 ****
- --- 1,6 ----
- +
- + /* @(#)roachmap.h 1.3 4/2/91 11:55:35 */
- +
- #include "roach000.xbm"
- #include "roach015.xbm"
- #include "roach030.xbm"
- ***************
- *** 22,27 ****
- --- 25,32 ----
- #include "roach315.xbm"
- #include "roach330.xbm"
- #include "roach345.xbm"
- +
- + #include "squish.xbm"
-
- #define ROACH_HEADINGS 24 /* number of orientations */
- #define ROACH_ANGLE 15 /* angle between orientations */
- *** xroach.c Tue Apr 02 11:59:18 1991
- --- ../xroach/xroach.c Tue Apr 02 11:53:42 1991
- ***************
- *** 12,21 ****
- --- 12,31 ----
- cc -o xroach roach.c -lX11 [-lsocketorwhatever] [-lm] [-l...]
-
- Dedicated to Greg McFarlane. (gregm@otc.otca.oz.au)
- +
- + Squish option contributed by Rick Petkiewizc (rick@locus.com)
- +
- + Virtual root code adapted from patch sent by Colin Rafferty who
- + borrowed it from Tom LaStrange. Several other folks sent similar
- + fixes.
- */
- +
- + /* @(#)xroach.c 1.5 4/2/91 11:53:31 */
- +
- #include <X11/Xlib.h>
- #include <X11/Xutil.h>
- #include <X11/Xos.h>
- + #include <X11/Xatom.h>
-
- #include <stdio.h>
- #include <math.h>
- ***************
- *** 49,54 ****
- --- 59,65 ----
- unsigned int display_width, display_height;
- int center_x, center_y;
- GC gc;
- + GC gutsGC;
- char *display_name = NULL;
- Pixel black, white;
-
- ***************
- *** 55,60 ****
- --- 66,74 ----
- int done = 0;
- int eventBlock = 0;
- int errorVal = 0;
- + Bool squishRoach = False;
- + Pixmap squishMap;
- + Bool squishWinUp = False;
-
- typedef struct Roach {
- RoachMap *rp;
- ***************
- *** 84,89 ****
- --- 98,104 ----
- int CalcRootVisible();
- int MarkHiddenRoaches();
- Pixel AllocNamedColor();
- + Window FindRootWindow();
-
- void
- main(ac, av)
- ***************
- *** 98,105 ****
- --- 113,123 ----
- float angle;
- XEvent ev;
- char *roachColor = "black";
- + char *gutsColor = NULL;
- int nVis;
- int needCalc;
- + Window squishWin;
- + XSetWindowAttributes xswa;
-
- /*
- Process command line options.
- ***************
- *** 118,123 ****
- --- 136,147 ----
- else if (strcmp(arg, "-roaches") == 0) {
- maxRoaches = strtol(av[++ax], (char **)NULL, 0);
- }
- + else if (strcmp(arg, "-squish") == 0) {
- + squishRoach = True;
- + }
- + else if (strcmp(arg, "-rgc") == 0) {
- + gutsColor = av[++ax];
- + }
- else {
- Usage();
- }
- ***************
- *** 142,148 ****
- }
-
- screen = DefaultScreen(display);
- ! rootWin = RootWindow(display, screen);
- black = BlackPixel(display, screen);
- white = WhitePixel(display, screen);
-
- --- 166,172 ----
- }
-
- screen = DefaultScreen(display);
- ! rootWin = FindRootWindow();
- black = BlackPixel(display, screen);
- white = WhitePixel(display, screen);
-
- ***************
- *** 164,179 ****
- --- 188,229 ----
- rp->cosine = cos(angle);
- }
-
- + /*
- + Create the squished pixmap
- + */
- + if (squishRoach) {
- + squishMap = XCreateBitmapFromData(display, rootWin,
- + squish_bits, squish_width, squish_height);
- + }
- +
- roaches = (Roach *)malloc(sizeof(Roach) * maxRoaches);
-
- gc = XCreateGC(display, rootWin, 0L, &xgcv);
- XSetForeground(display, gc, AllocNamedColor(roachColor, black));
- XSetFillStyle(display, gc, FillStippled);
- +
- + if (squishRoach && gutsColor != NULL) {
- + gutsGC = XCreateGC(display, rootWin, 0L, &xgcv);
- + XSetForeground(display, gutsGC, AllocNamedColor(gutsColor, black));
- + XSetFillStyle(display, gutsGC, FillStippled);
- + }
- + else
- + gutsGC = gc;
-
- while (curRoaches < maxRoaches)
- AddRoach();
-
- XSelectInput(display, rootWin, ExposureMask | SubstructureNotifyMask);
- +
- + if (squishRoach) {
- + xswa.event_mask = ButtonPressMask;
- + xswa.override_redirect = True;
- + squishWin = XCreateWindow(display, rootWin, 0, 0,
- + display_width, display_height, 0,
- + CopyFromParent, InputOnly, CopyFromParent,
- + CWOverrideRedirect | CWEventMask, &xswa);
- + XLowerWindow(display, squishWin);
- + }
-
- needCalc = 1;
- while (!done) {
- ***************
- *** 184,195 ****
- if (needCalc) {
- needCalc = CalcRootVisible();
- }
- ! nVis = MarkHiddenRoaches();
- if (nVis) {
- ev.type = SCAMPER_EVENT;
- }
- else {
- ! DrawRoaches();
- eventBlock = 1;
- XNextEvent(display, &ev);
- eventBlock = 0;
- --- 234,257 ----
- if (needCalc) {
- needCalc = CalcRootVisible();
- }
- ! if (needCalc)
- ! nVis = 0;
- ! else
- ! nVis = MarkHiddenRoaches();
- if (nVis) {
- ev.type = SCAMPER_EVENT;
- + if (!squishWinUp && squishRoach) {
- + XMapWindow(display, squishWin);
- + squishWinUp = True;
- + }
- }
- else {
- ! if (squishWinUp && squishRoach) {
- ! XUnmapWindow(display, squishWin);
- ! squishWinUp = False;
- ! }
- ! if (needCalc == 0)
- ! DrawRoaches();
- eventBlock = 1;
- XNextEvent(display, &ev);
- eventBlock = 0;
- ***************
- *** 207,218 ****
- XSync(display, False);
- break;
-
- - case Expose:
- - case MapNotify:
- case UnmapNotify:
- case ConfigureNotify:
- needCalc = 1;
- break;
-
- }
- }
- --- 269,288 ----
- XSync(display, False);
- break;
-
- case UnmapNotify:
- + if (ev.xunmap.window != squishWin)
- + needCalc = 1;
- + break;
- +
- + case MapNotify:
- + case Expose:
- case ConfigureNotify:
- needCalc = 1;
- break;
- +
- + case ButtonPress:
- + checkSquish(&ev);
- + break;
-
- }
- }
- ***************
- *** 233,238 ****
- --- 303,310 ----
- USEPRT(" -rc roachcolor\n");
- USEPRT(" -roaches numroaches\n");
- USEPRT(" -speed roachspeed\n");
- + USEPRT(" -squish\n");
- + USEPRT(" -rgc roachgutscolor\n");
-
- exit(1);
- }
- ***************
- *** 256,261 ****
- --- 328,391 ----
- }
-
- /*
- + Find the root or virtual root window.
- + */
- + Window
- + FindRootWindow()
- + {
- + Window rootWin;
- + Window realRoot;
- + Atom swmVroot;
- + Window rootReturn, parentReturn, *children;
- + unsigned int numChildren;
- + int cx;
- + Atom actualType;
- + Atom actualFormat;
- + unsigned long nItems;
- + unsigned long bytesAfter;
- + Window *newRoot;
- +
- + /*
- + Get real root window.
- + */
- + realRoot = rootWin = RootWindow(display, screen);
- +
- + /*
- + Get atom for virtual root property. If the atom doesn't
- + exist, we can assume the corresponding property does not
- + exist.
- + */
- + swmVroot = XInternAtom(display, "__SWM_VROOT", True);
- +
- + if (swmVroot == None)
- + return rootWin;
- +
- + /*
- + Run children of root, looking for a virtual root.
- + */
- + XQueryTree(display, rootWin, &rootReturn, &parentReturn,
- + &children, &numChildren);
- + for (cx=0; cx<numChildren; cx++) {
- + newRoot = NULL;
- + nItems = 0;
- + if (XGetWindowProperty(display, children[cx], swmVroot, 0L, 1L, False,
- + XA_WINDOW, &actualType, &actualFormat, &nItems,
- + &bytesAfter, &newRoot) == Success && actualFormat != None) {
- + if (nItems >= 1) {
- + rootWin = *newRoot;
- + }
- + if (newRoot) {
- + XFree(newRoot);
- + }
- + }
- + if (rootWin != realRoot) break;
- + }
- + XFree(children);
- +
- + return rootWin;
- + }
- +
- + /*
- Generate random integer between 0 and maxVal-1.
- */
- int
- ***************
- *** 404,410 ****
- for (rx=0; rx<curRoaches; rx++) {
- roach = &roaches[rx];
-
- ! if (roach->intX >= 0) {
- XClearArea(display, rootWin, roach->intX, roach->intY,
- roach->rp->width, roach->rp->height, False);
- }
- --- 534,540 ----
- for (rx=0; rx<curRoaches; rx++) {
- roach = &roaches[rx];
-
- ! if (roach->intX >= 0 && roach->rp != NULL) {
- XClearArea(display, rootWin, roach->intX, roach->intY,
- roach->rp->width, roach->rp->height, False);
- }
- ***************
- *** 505,515 ****
- */
- covered = XCreateRegion();
- for (wx=0; wx<nChildren; wx++) {
- ! if (XEventsQueued(display, QueuedAlready)) return 1;
- errorVal = 0;
- XGetWindowAttributes(display, children[wx], &wa);
- if (errorVal) continue;
- ! if (wa.map_state == IsViewable) {
- XGetGeometry(display, children[wx], &dummy, &winX, &winY,
- &winWidth, &winHeight, &borderWidth, &depth);
- if (errorVal) continue;
- --- 635,648 ----
- */
- covered = XCreateRegion();
- for (wx=0; wx<nChildren; wx++) {
- ! if (XEventsQueued(display, QueuedAlready)) {
- ! XDestroyRegion(covered);
- ! return 1;
- ! }
- errorVal = 0;
- XGetWindowAttributes(display, children[wx], &wa);
- if (errorVal) continue;
- ! if (wa.class == InputOutput && wa.map_state == IsViewable) {
- XGetGeometry(display, children[wx], &dummy, &winX, &winY,
- &winWidth, &winHeight, &borderWidth, &depth);
- if (errorVal) continue;
- ***************
- *** 606,609 ****
- --- 739,783 ----
- }
-
- return pix;
- + }
- +
- + /*
- + * squishCheck - Check to see if we have to squish any roaches.
- + */
- + checkSquish(buttonEvent)
- + XButtonEvent *buttonEvent;
- + {
- + int x, y;
- + int i;
- + int rx;
- + Roach *r;
- + /* */
- + x = buttonEvent->x;
- + y = buttonEvent->y;
- +
- + for (rx=0; rx<curRoaches; rx++) {
- + r = &roaches[rx];
- + if (r->rp == NULL) continue;
- +
- + if (x > r->intX &&
- + x < (r->intX + r->rp->width) &&
- + y > r->intY &&
- + y < (r->intY + r->rp->height)) {
- + XSetStipple(display, gutsGC, squishMap);
- + XSetTSOrigin(display, gutsGC, r->intX, r->intY);
- + XFillRectangle(display, rootWin, gutsGC,
- + r->intX, r->intY, squish_width, squish_height);
- +
- + /*
- + * Delete the roach
- + */
- + for (i = rx; i < curRoaches - 1; i++)
- + roaches[i] = roaches[i + 1];
- +
- + curRoaches--;
- + rx--;
- + }
- + }
- +
- + return;
- }
- *** xroach.man Tue Apr 02 12:26:11 1991
- --- ../xroach/xroach.man Tue Apr 02 12:46:43 1991
- ***************
- *** 9,15 ****
- displays disgusting cockroaches on your root window. These creapy crawlies
- scamper
- around until they find a window to hide under. Whenever you move or iconify
- ! a window, the exposed beetles again scamper for cover.
- .SH OPTIONS
- .TP 8
- .B \-display \fIdisplay_name\fB
- --- 9,15 ----
- displays disgusting cockroaches on your root window. These creapy crawlies
- scamper
- around until they find a window to hide under. Whenever you move or iconify
- ! a window, the exposed orthopteras again scamper for cover.
- .SH OPTIONS
- .TP 8
- .B \-display \fIdisplay_name\fB
- ***************
- *** 26,31 ****
- --- 26,38 ----
- .TP 8
- .B \-roaches \fInum_roaches\fB
- This is the number of the little critters. Default is 10.
- + .TP 8
- + .B \-squish
- + Enables roach squishing. Point and shoot with any mouse button.
- + .TP 8
- + .B \-rgc \fIroach_gut_color\fB
- + Sets color of the guts that spill out of squished roaches. We recommend
- + yellowgreen.
- .SH BUGS
- As given by the -roaches option. Default is 10.
- .SH COPYRIGHT
-